package cn.mw.cmdb.param;

import cn.mw.cmdb.entity.ModelTemplateInfo;
import cn.mw.cmdb.service.ServiceChoose;
import cn.mw.cmdb.service.impl.ModelTemplateServiceImpl;
import cn.mw.cmdb.util.CMDBTool;
import cn.mw.components.mongodb.entity.CriteriaOpsType;
import cn.mw.components.mongodb.entity.SearchParam;
import cn.mw.components.mongodb.entity.SubCondition;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.List;

@Data
public class TemplateSearchParam extends SearchParam implements ServiceChoose, SearchParamConvert, Serializable {

    //模板名称
    protected String templateName;
    //监控方式
    protected Integer monitorMode;
    //厂商Id
    protected String brandId;
    //规格型号Id
    protected String specificationId;
    //导出的字段
    private List<String> header;
    //是否导出模板
    private boolean isExportTemp;

    @Override
    public String getServiceId() {
        return ModelTemplateServiceImpl.ID;
    }

    @Override
    public void convert() {
        //模板名称
        String tempName = getTemplateName();
        if (StringUtils.hasText(tempName)) {
            this.addSubCondition(CMDBTool.getFieldName(ModelTemplateInfo::getTemplateName)
                    , new SubCondition(CriteriaOpsType.is.name(), tempName));
        }
        //监控方式
        Integer mode = getMonitorMode();
        if (mode != null) {
            this.addSubCondition(CMDBTool.getFieldName(ModelTemplateInfo::getMonitorMode)
                    , new SubCondition(CriteriaOpsType.is.name(), mode));
        }
        //厂商id
        String vendorId = getBrandId();
        if (StringUtils.hasText(vendorId)) {
            this.addSubCondition(CMDBTool.getFieldName(ModelTemplateInfo::getBrandId)
                    , new SubCondition(CriteriaOpsType.is.name(), vendorId));
        }
        //规格型号id
        String specId = getSpecificationId();
        if (StringUtils.hasText(specId)) {
            this.addSubCondition(CMDBTool.getFieldName(ModelTemplateInfo::getSpecificationId)
                    , new SubCondition(CriteriaOpsType.is.name(), specId));
        }

    }
}
